class Solution
{
public:
    int edgeScore(vector<int> &edges)
    {
        unordered_map<int, long long> scores;
        for (int i = 0; i < edges.size(); ++i)
        {
            scores[edges[i]] += i;
        }
        long long maxScore = 0;
        int maxScoreNode = INT_MAX;
        for (auto &[node, score] : scores)
        {
            if (score > maxScore)
            {
                maxScore = score;
                maxScoreNode = node;
            }
            else if (score == maxScore)
            {
                maxScoreNode = min(maxScoreNode, node);
            }
        }
        return maxScoreNode;
    }
};